草庐IT

Python Django 模板 : Iterate Through List

全部标签

c++ - 模板化友元声明在 g++ 5.4.0 下不起作用——编译器错误或错误代码?

下面是一些C++代码,在我的Mac(Xcode10.210E125/AppleLLVM版本10.0.1(clang-1001.0.46.4))上编译没有错误,但给出了编译器错误消息(显示下面)在我的Linux机器上(g++(Ubuntu5.4.0-6ubuntu1~16.04.11)5.4.020160609)。我的问题是,这是g++5.4.0中的编译器错误,还是我在代码中做错了什么?g++5.4.0的编译器错误是:$g++template_friend.cpptemplate_friend.cpp:Ininstantiationof‘classSubClass’:template_f

c++ - 推导用户定义值模板参数(C++2a,P0732R2)

我正在尝试使用带有-std=c++2a的GCC9.1来获取推导的用户定义类的模板参数的值(http://wg21.link/p0732r2)。structuser_type{inta;constexpruser_type(inta):a(a){}};templatestructvalue{};templatevoidf(valuearg){}voidg(){f(value());//errorhere}编译器资源管理器:https://godbolt.org/z/6v_p_R我得到错误:source>:8:30:note:templateargumentdeduction/substi

c++ - 模板类中引用的引用类型是什么

这个问题在这里已经有了答案:Conciseexplanationofreferencecollapsingrulesrequested:(1)A&&->A&,(2)A&&&->A&,(3)A&&&->A&,and(4)A&&&&->A&&(2个答案)关闭3年前。在下面的代码中,a和b的类型是什么?templatestructA{T&a;Tb;};intmain(){inti=1;Aa{i,i};return1;}我使用了这篇文章中的代码,它可以给出变量的类型。->post但是,它说这两种类型都是iconst&。intmain(){inti=1;Aa{i,i};std::cout()()

带有 std::enable_if 的 C++ 可变参数模板部分模板特化

ITNOA我的问题是如何在可变参数模板部分模板特化场景中使用std::enable_if?例如,我有一个类使用如下所示的可变参数模板部分特化/***Commoncase.*/templatestructfoo;/***Finalsuperclassforfoo.*/templatestructfoo{voidfunc(){}};/***Regularfooclass.*/templatestructfoo:publicfoo{typedefsuperfoo;voidfunc(){coutsuper::templatefunc();}}它工作正常,但如果H是整数类型,我想要特定的部分特化

c++ - 使用非捕获 lambda 作为可变参数模板函数的函数指针参数给出 "no matching function call"

我目前正在尝试为ecs编写“foreachwith”。templatevoidforeach(void(*func)(Entitye,T...args)){std::vectorintersection;//...Findallentitieswithallthetypesfor(size_ti=0;i(intersection[i])...);}它与函数参数配合得很好voidfoo(Entitye,inti){setComp(e,(int)e);}foreach(foo);//Worksasexpected但不能像lambda那样复制和粘贴相同的函数foreach(//eveniff

c++ - 为什么 `uint64_t` 的模板特化与 Mac 平台上的 `unsigned long` 不匹配?

这个问题在这里已经有了答案:longlongintvs.longintvs.int64_tinC++(3个答案)关闭3年前。为什么以下代码片段在Mac平台上使用clang++编译失败?sizeofunsignedlong和uint64_t都是8,所以我认为它们是同一类型。那么为什么编译认为Serializer是抽象的吗?因为我定义了Serializer,Serializer,Serializer,Serializer,Serializer,Serializer,Serializer,Serializer,有没有办法解决这个问题并避免定义更多类型,如Serializer?错误信息如下,c

c++ - 我们可以专门化类模板的枚举(类型)成员吗?

Cppreference声称,除其他事项外,您可以专注于memberenumerationofaclasstemplate由于没有提供示例,我试图猜测如何做到这一点。我最终得到了以下结果:templatestructA{enumE:int;};templateenumA::E:int{a,b,c};Clang(带有-std=c++17-pedantic-errors的8.0.0)编译它。GCC(9.1with-std=c++17-pedantic-errors)拒绝代码error:templatespecializationof'enumA::E'notallowedbyISOC++[

c++ - 使用可变参数模板函数围绕类实现基于 pImpl 的包装器

总结我正在编写一个库和一个客户端应用程序。在库中,我尝试围绕另一个静态链接的第三方库(特别是spdlog)编写包装器,并尝试使用pImpl惯用语将其完全隐藏在客户端应用程序中。问题是第三方库使用可变模板函数,所以我也需要在我的库中。背景我对包装器的第一次尝试非常简单直接,但后来我在客户端应用程序中收到“没有这样的文件或目录”错误,因为第三方header包含在我的库header中。我接下来尝试创建一个pImpl类并让它进行编译,但在客户端中我再次遇到“undefinedreference”链接器错误。将实现的源代码拉到我的包装器的header中让我回到最初的“没有这样的文件”问题。对此进

c++ - 帮助在 std::map 中存储模板类的 intrusive_ptr

我在boost::intrusive_ptr中包含一个Locker类型的小模板类,我想将其存储在std::map中:templateboolLockerManager::AddData(conststd::string&id,T*pData){boost::intrusive_ptr>lPtr(Locker(pData));//Line359-compilesmMap.insert(make_pair(id,lPtr));//Line361-giveserror}Locker只是一个容器类;它的构造函数看起来像:templateLocker::Locker(T*pData):Intru

c++ - 通过模板基类专门化模板

我正在编写一个模板,我试图为其提供一个类的特化,该类本身就是一个模板类。在使用它时,我实际上是用模板化类的衍生物实例化它,所以我有这样的东西:templatestructArg{staticinlineconstsize_tSize(constT*arg){returnsizeof(T);}staticinlineconstT*Ptr(constT*arg){returnarg;}};templatestructArg>{staticinlineconstsize_tSize(constWrap*arg){returnsizeof(T);}staticinlineconstT*Ptr(